<template>
  <view>
    <!-- 顶部搜索区域 -->
     <view class="search-box">
        <my-search></my-search>
     </view>
    <!-- 首页轮播图区域 -->
      <swiper :indicator-dots="true" :autoplay="true" :duration="1000" :interval="3000" circular="true">
        <swiper-item v-for="(item,index) in swiperList" :key="index">
          <navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`" class="swiper-item"><image :src="item.image_src" alt="" /></navigator>
        </swiper-item>
      </swiper>
      <!-- 分类导航区域 -->
      <view class="nav-list">
        <view @click="navClickHandler(item.name)" class="nav-item" v-for="(item,index) in navList" :key="index">
          <image :src="item.image_src"></image>
        </view>
      </view>
      <!-- 楼层区域 -->
      <view class="floor-list">
        <view class="floor-item" v-for="(item,index) in floorList" :key="index">
          <view class="floor-title">
            <img :src="item.floor_title.image_src" alt="" />
          </view>
          <view class="floor-content">
            <navigator class="content-left" :url="item.product_list[0].navigator_url">
              <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
            </navigator>
            <view class="content-right">
              <navigator v-for="(i,index) in item.product_list.slice(1)" :key="index" :url="i.navigator_url" class="right-item">
                <image :src="i.image_src" :style="{width:i.image_width + 'rpx'}" mode="widthFix" />
              </navigator>
            </view>
          </view>
        </view>
      </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        // 轮播图数据
        swiperList:[],
        // 首页分类导航的数据
        navList:[],
        // 楼层数据
        floorList:[]
      }
    },
    onLoad(){
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
    async getSwiperList(){
        const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
        if(res.meta.status !==200){
       uni.$showMsg()
        }else{
          this.swiperList = res.message
          uni.$showMsg('数据请求成功')
        }
        
      },
     async getNavList(){
        const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
        if(res.meta.status !==200){
        uni.$showMsg()
         }else{
           this.navList = res.message
           uni.$showMsg('数据请求成功')
          
         }
      },
      async getFloorList(){
        const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status !==200){
        uni.$showMsg()
         }else{
           res.message.forEach(item =>{
             item.product_list.forEach(i =>{
               i.navigator_url = '/subpkg/goods_list/goods_list?' +  i.navigator_url.slice(-8,0)
             })
           })
           this.floorList = res.message
           uni.$showMsg('数据请求成功')
          
         }
      },
      navClickHandler(name){
       if(name==='分类'){
         uni.switchTab({
           url:'/pages/cate/cate'
         })
       }
      }
    }
  }
</script>

<style lang="scss">
swiper{
  height: 330rpx;
  .swiper-item,image{
    width: 100%;
    height: 100%;
  }
}
.nav-list{
  display: flex;
  justify-content: space-around;
  margin: 15rpx 0;
  .nav-item{
    image{
      width: 128rpx;
      height: 140rpx;
    }
   }
  }
.floor-list{
  .floor-item{
    padding: 10rpx;
    margin-bottom: 20rpx;
    .floor-title{
      image{
        width: 100%;
        height: 60rpx;
      }
    }
    .floor-content{
      display: flex;
      .content-left{
        display: flex;
        margin-right: 10rpx;
      }
      .content-right{
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
      right-item{
        
      }
        
      }
    }
  }
}
.search-box{
  position: sticky;
  top: 0;
  z-index: 999;
}
</style>
